package com.woniuxy.service.impl;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.dao.DrugDao;
import com.woniuxy.dao.InspectDao;
import com.woniuxy.entity.Drug;
import com.woniuxy.entity.Inspect;
import com.woniuxy.entity.PageBean;
import com.woniuxy.service.DrugService;
import com.woniuxy.service.InspectService;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class InspectServiceImpl implements InspectService {

    @Autowired
    InspectDao inspectDao;


    @Override
    public PageBean<Inspect> getAllInspectsPageByCondition(Inspect inspect, int pageIndex, int pageSize) {
        try {
            PageBean<Inspect> pageBean = new PageBean<>();
//        存储当前页
            pageBean.setPageIndex(pageIndex);
//        存储页大小
            pageBean.setPageSize(pageSize);
//        存储总条数
            int pageCount = inspectDao.selectInspectCount(inspect);
            pageBean.setTotalRecord(pageCount);

            pageBean.setBeanList(inspectDao.selectInspectsByCondition(inspect, pageIndex, pageSize));
            return pageBean;
        } catch (PersistenceException e) {
            throw new serviceException("系统维护中");
        }
    }
}
